﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace PrinteMaster
{
    public partial class 通用信息修改窗口 : Form
    {
        private string _账号 = "";
        private string _密码 = "";
        private string _姓名 = "";
        private string _手机号 = "";
        private double _余额 = 0.0;
        public static 通用信息修改窗口 create(string 账号, string 密码, string 姓名, string 手机号, double 余额)
        {
            var t = new 通用信息修改窗口();
            t.textBox密码.Text = 密码;
            t.textBox手机号.Text = 手机号;
            t.textBox姓名.Text = 姓名;
            t.textBox余额.Text = 余额.ToString();
            t.textBox账号.Text = 账号;
            t.ShowDialog();
            return t;
        }
        public 通用信息修改窗口()
        {
            InitializeComponent();
        }

        private void label1_Click(object sender, EventArgs e)
        {

        }

        private void 通用信息修改窗口_Load(object sender, EventArgs e)
        {

        }

        private void textBox5_TextChanged(object sender, EventArgs e)
        {
        
        }

        private void label6_Click(object sender, EventArgs e)
        {
        
        }

        private void button1_Click(object sender, EventArgs e)
        {
            
            double 余额 = 0.0;
            try
            {
                余额 = Convert.ToDouble(textBox余额.Text);
            }
            catch (FormatException fe)
            {
                MessageBox.Show("余额输入不合法=>"+fe.Message);
                return;
            }
            if(textBox手机号.Text.Length != 11)
            {
                MessageBox.Show("手机号位数必须为11位！");
                return;
            }
            if (textBox姓名.Text.Length > 10)
            {
                MessageBox.Show("姓名必须小于10位");
                return;
            }
            if (textBox密码.Text.Length < 6)
            {
                MessageBox.Show("密码必须大于6位");
                return;

            }
            string username;
            if (DataBase.getInstance().isUserId(textBox账号.Text, out username) != DataBase.Error.ok)
            {
                MessageBox.Show("没有该账号!");
            }
            var str = string.Format(
                "update 会员简 set 余额={0},密码='{1}',手机号='{2}',姓名='{3}' where 账号 = '{4}'"
                ,textBox余额.Text,textBox密码.Text
                ,textBox手机号.Text,textBox姓名.Text,textBox账号.Text);
            try
            {
                DataSet req = MySqlHelper.GetDataSet(MySqlHelper.Conn, CommandType.Text, str, null);
                MessageBox.Show("通用信息修改成功!");
                //Log.managerLog("为" + textBox姓名.Text + "注册账号", "老板模式", "老板模式", "老板模式");
                Log.managerLog("==================================", "老板模式", "老板模式", "老板模式");
                Log.managerLog("为" + username + "修改通用信息", "老板模式", "老板模式", "老板模式");
                Log.managerLog("设置余额=>" + textBox余额.Text + "修改通用信息", "老板模式", "老板模式", "老板模式");
                Log.managerLog("设置手机号=>" + textBox手机号.Text + "修改通用信息", "老板模式", "老板模式", "老板模式");
                Log.managerLog("设置姓名=>" + textBox姓名.Text + "修改通用信息", "老板模式", "老板模式", "老板模式");
                Log.managerLog("设置密码=>" + textBox密码.Text + "修改通用信息", "老板模式", "老板模式", "老板模式");
                Log.managerLog("==================================", "老板模式", "老板模式", "老板模式");
                this.Close();
            }
            catch (Exception ex) { MessageBox.Show("数据库出错"+ex.Message); }

        }
    }
}
